package com.example.user.ctl;

import com.example.user.client.ProductClient;
import com.example.user.dto.ProductDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

/**
 * @title: UserCtl
 * @description:
 * @author: brucewong
 * @version: 1.0
 * @date：2019/10/10 21:34
 */
@RestController
@RequestMapping("/user")
public class UserCtl {
    @Autowired
    ProductClient productClient;

    @Value("foo")
    String foo;

    @GetMapping("/products/{id}")
    public ProductDTO findProduct(@PathVariable("id") String id){
        return productClient.findProduct(foo);
    }

    @GetMapping("/product")
    public ProductDTO findProduct(@RequestParam("id") String id, @RequestParam("name") String name){
        return productClient.findProduct(id, name);
    }

    @PostMapping("/product/add")
    public ProductDTO add(@RequestBody ProductDTO productDTO){
        return productClient.add(productDTO);
    }

}